package com.tonann.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tonann.common.annotation.Log;
import com.tonann.common.core.controller.BaseController;
import com.tonann.common.core.domain.AjaxResult;
import com.tonann.common.enums.BusinessType;
import com.tonann.app.domain.AppGateway;
import com.tonann.app.service.IAppGatewayService;
import com.tonann.common.utils.poi.ExcelUtil;
import com.tonann.common.core.page.TableDataInfo;

/**
 * 运行网关Controller
 * 
 * @author kunchan
 * @date 2022-10-09
 */
@RestController
@RequestMapping("/app/gateway")
public class AppGatewayController extends BaseController
{
    @Autowired
    private IAppGatewayService appGatewayService;

    /**
     * 查询运行网关列表
     */
    @PreAuthorize("@ss.hasPermi('app:gateway:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppGateway appGateway)
    {
        startPage();
        List<AppGateway> list = appGatewayService.selectAppGatewayList(appGateway);
        return getDataTable(list);
    }

    /**
     * 查询运行网关列表
     */
    @PreAuthorize("@ss.hasPermi('app:gateway:list')")
    @GetMapping("/all")
    public AjaxResult all()
    {
        List<AppGateway> list = appGatewayService.selectAppGatewayList(new AppGateway());
        return AjaxResult.success(list);
    }

    /**
     * 导出运行网关列表
     */
    @PreAuthorize("@ss.hasPermi('app:gateway:export')")
    @Log(title = "运行网关", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppGateway appGateway)
    {
        List<AppGateway> list = appGatewayService.selectAppGatewayList(appGateway);
        ExcelUtil<AppGateway> util = new ExcelUtil<AppGateway>(AppGateway.class);
        util.exportExcel(response, list, "运行网关数据");
    }

    /**
     * 获取运行网关详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:gateway:query')")
    @GetMapping(value = "/{gatewayId}")
    public AjaxResult getInfo(@PathVariable("gatewayId") Long gatewayId)
    {
        return AjaxResult.success(appGatewayService.selectAppGatewayByGatewayId(gatewayId));
    }

    /**
     * 新增运行网关
     */
    @PreAuthorize("@ss.hasPermi('app:gateway:add')")
    @Log(title = "运行网关", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppGateway appGateway)
    {
        return toAjax(appGatewayService.insertAppGateway(appGateway));
    }

    /**
     * 修改运行网关
     */
    @PreAuthorize("@ss.hasPermi('app:gateway:edit')")
    @Log(title = "运行网关", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppGateway appGateway)
    {
        return toAjax(appGatewayService.updateAppGateway(appGateway));
    }

    /**
     * 删除运行网关
     */
    @PreAuthorize("@ss.hasPermi('app:gateway:remove')")
    @Log(title = "运行网关", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gatewayIds}")
    public AjaxResult remove(@PathVariable Long[] gatewayIds)
    {
        return toAjax(appGatewayService.deleteAppGatewayByGatewayIds(gatewayIds));
    }

    /**
     * 获取所有网关
     */
    @PreAuthorize("@ss.hasPermi('app:gateway:list')")
    @GetMapping("/all/{gatewayId}")
    public AjaxResult getAll(@PathVariable Long gatewayId)
    {
        if (gatewayId == null){
            AppGateway appGateway = new AppGateway();
            appGateway.setDelFlag("0");
            return AjaxResult.success(appGatewayService.selectAppGatewayList(appGateway));
        }
        return AjaxResult.success(appGatewayService.getAll(gatewayId));
    }
}
